/**
 * 
 */
package com.baijia.tianxiao.push.model;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;

/**
 * @author leiruiqi
 *
 * 推送绑定记录模型，查询绑定是找出最新的绑定记录
 */
public class PushBindRecord implements Serializable{
	

	/**
	 * 
	 */
	private static final long serialVersionUID = 6522851291286091148L;
	

	private Long id;
	
	/**
	 * 用户类型，见UserTypeEnum
	 */
	private String userType;
	
	/**
	 * 用户类型对应的Id，字符串类型自由组装，同种类型的所有id必须唯一
	 */
	private String userId;
	
	
	
	/**
	 * 绑定设备的具体类型，见DeviceType;
	 */
	private String deviceType;
	
	/**
	 * 设备的唯一编号
	 */
	private String deviceId;
		
	/**
	 * 绑定时间
	 */
	private Date bindTime;
	
	/**
	 * 绑定状态
	 */
	private Integer bindStatus;
	
	/**
	 * 解绑时间时间
	 */
	private Date unbindTime;
	
	
	/**
	 * 绑定推送通道的相关信息模型,key是渠道类型标志，见ChannelTypeEnum
	 */
	private List<PushBindChannel> channelList;
	
	/**
	 * 绑定推送渠道模型的json格式存储,channelMap 属性的json字符串形式
	 */
	private String channels;
	
	private String deviceAttribute;
	
	
	
	
	
	public void buildChannelMap(){
		if(channelList == null){
			channelList = new ArrayList<PushBindChannel>();
		}
		else{
			channelList.clear();;
		}
		if(StringUtils.isNoneBlank(channels)){
			//List<PushBindChannel> list;
			try {
				channelList = JSON.parseObject(channels, new TypeReference<List<PushBindChannel>>() {
				});
			} catch (Exception e) {
				return;
			}
			
		}
	}
	
	public void buildChanels(){
		channels = null;
		if(CollectionUtils.isNotEmpty(channelList)){
			try {
				channels = JSON.toJSONString(channelList);
			} catch (Exception e) {
				return;
			}
		}
	}
	
	

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUserType() {
		return userType;
	}

	public void setUserType(String userType) {
		this.userType = userType;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public String getChannels() {
		return channels;
	}

	public void setChannels(String channels) {
		this.channels = channels;
	}

	

	public String getDeviceType() {
		return deviceType;
	}

	public void setDeviceType(String deviceType) {
		this.deviceType = deviceType;
	}

	public Date getBindTime() {
		return bindTime;
	}

	public void setBindTime(Date bindTime) {
		this.bindTime = bindTime;
	}

	public Integer getBindStatus() {
		return bindStatus;
	}

	public void setBindStatus(Integer bindStatus) {
		this.bindStatus = bindStatus;
	}

	public Date getUnbindTime() {
		return unbindTime;
	}

	public void setUnbindTime(Date unbindTime) {
		this.unbindTime = unbindTime;
	}

	public List<PushBindChannel> getChannelList() {
		return channelList;
	}

	public void setChannelList(List<PushBindChannel> channelList) {
		this.channelList = channelList;
	}

	public String getDeviceId() {
		return deviceId;
	}

	public void setDeviceId(String deviceId) {
		this.deviceId = deviceId;
	}

	public String getDeviceAttribute() {
		return deviceAttribute;
	}

	public void setDeviceAttribute(String deviceAttribute) {
		this.deviceAttribute = deviceAttribute;
	}

	
}
